/*********************************************************************************************************
**
**                                   GJB 标准测试集
**
**                               Copyright All Rights Reserved
**
**--------------文件信息--------------------------------------------------------------------------------
**
** 文   件   名: gjb_S0100902GN_3.c
**
** 文件创建日期: 2021 年 1 月 22 日
**
** 描        述: 以永久阻塞方式等待条件变量功能测试
*********************************************************************************************************/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>

//#include "gjb.h"

static int err_count_cv_9023;

pthread_cond_t cond2_cv_9023 = PTHREAD_COND_INITIALIZER;                        /* cond used by the two threads */
pthread_mutex_t mutex3_cv_9023 = PTHREAD_MUTEX_INITIALIZER;                     /* cond used by the two threads */

void * thread2_cv_9023(void *tmp)
{
    int    rc = 0;

    /*
     * Wait on the cond var. This will not return, as nobody signals
     */
    rc = pthread_cond_wait(&cond2_cv_9023, &mutex3_cv_9023);
    if (rc == EPERM) {
        printf("test pass,pthread_cond_wait return EPERM \n");

    } else {
        printf("test failed.pthread_cond_wait should return EPERM  , but return %d\n",rc);
        err_count_cv_9023++;
        return (void *)-1;
    }

    return NULL;
}

int main(int argc, char **argv)
{
    pthread_t low_id;
    int       rc = 0;

    /*
     * Create a new thread with default attributes
     */
    rc = pthread_create(&low_id, NULL, thread2_cv_9023, NULL);
    if(rc != 0) {
        printf("pthread_create\n");
        goto __errno_handle;
    }

    /*
     * Let the other thread run
     */
    sleep(2);

    // pthread_kill(low_id, SIGTERM);
    pthread_join(low_id, SIGTERM);
    if (err_count_cv_9023) {
        goto __errno_handle;
    }

    printf("<RSLT>..................................................[(0)]\n \n \n");

    return  (0);   

__errno_handle:
    printf("<RSLT>..................................................[(-1)]\n \n \n");
    return  (-1);
}
